<template>
  <div class="disposeOrder" :class="$style.wrap">
    <ContentWrap>
      <FormContainer :column="5">
        <el-form
          ref="formOrder"
          :model="formData"
          :rules="formRules"
          label-width="110px"
        >
          <el-form-item prop="nextHandler" label="处理人">
            <SearchSelectPicker
              url="/call-center/api/v1/staffInfo/page"
              placeholder="请选择"
              lable-name="staffName"
              value-name="accountNo"
              :value.sync="formData.nextHandler"
              :lable.sync="formData.nextHandlerName"
              multiple
              collapse-tags
            ></SearchSelectPicker>
          </el-form-item>
          <!-- <el-form-item prop="nextHandlerPlatformNo" show label="处理人工号">
            <el-input v-model.trim="formData.nextHandlerPlatformNo" placeholder="请输入处理人工号" clearable />
          </el-form-item> -->
          <el-form-item prop="handlerGroupNo" label="处理人业务组">
            <el-select v-model="formData.handlerGroupNo" filterable clearable placeholder="请选择业务组">
              <el-option
                v-for="item in businessOptions"
                :key="item.id"
                :label="item.groupName"
                :value="item.groupNo"
              />
            </el-select>
          </el-form-item>
          <el-form-item prop="" label="处理人岗位">
            <CustomDictSelect
              placeholder="请选择处理人岗位"
              dict-type-code="DEPT_POST_CODE"
              bind-name="dictName"
              bind-value="dictCode"
              filterable
              :echo-value.sync="formData.handlerPostCode"
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="contactName" label="联系人">
            <el-input v-model="formData.contactName" clearable placeholder="联系人" />
          </el-form-item>
          <el-form-item prop="contactPhone" label="联系电话">
            <el-input v-model.trim="formData.contactPhone" clearable placeholder="联系电话" />
          </el-form-item>
          <el-form-item prop="nickname" label="顾客ID">
            <el-input v-model.trim="formData.nickname" clearable placeholder="顾客ID" />
          </el-form-item>
          <el-form-item prop="orderCode" label="平台订单号">
            <el-input v-model.trim="formData.orderCode" clearable placeholder="多个平台订单号用英文逗号分隔" />
          </el-form-item>
          <el-form-item prop="ecOrderNumber" label="电商订单编号">
            <el-input v-model.trim="formData.ecOrderNumber" clearable placeholder="多个平电商订单编号用英文逗号分隔" />
          </el-form-item>

          <el-form-item prop="workOrderCode" label="工单编号">
            <el-input v-model.trim="formData.workOrderCode" clearable placeholder="工单编号" />
          </el-form-item>
          <el-form-item prop="workOrderState" label="工单状态">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="WORK_ORDER_STATUS"
              bind-name="dictName"
              bind-value="dictCode"
              collapse-tags
              multiple
              filterable
              :echo-value.sync="formData.workOrderState"
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="dispatchReceiveState" label="派单接收状态" hidden>
            <el-select v-model="formData.dispatchReceiveState" filterable clearable>
              <el-option value="01" label="未接收" />
              <el-option value="02" label="已接收" />
            </el-select>
          </el-form-item>
          <el-form-item prop="ccReceiveState" label="抄送接收状态">
            <el-select v-model="formData.ccReceiveState" filterable clearable>
              <el-option value="01" label="未接收" />
              <el-option value="02" label="已接收" />
            </el-select>
          </el-form-item>
          <el-form-item prop="processRate" label="维修进度">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="PROCESS_RATE"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.processRate"
              collapse-tags
              multiple
              filterable
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="buyChannel" label="购买渠道">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="PURCHASE_CHANNEL"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.buyChannel"
              filterable
              @on-change="buyChannelHandle"
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="channelType" label="联系渠道">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="CHANNEL_TYPE"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.channelType"
              filterable
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="businessType1" label="一级业务类型">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="FIRST_LEVEL_BUSINESS_TYPE"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.businessType1"
              filterable
            ></CustomDictSelect>
            <!-- @on-change="initBusinessType2" -->
            <!-- <el-select v-model="formData.businessType1" filterable clearable :loading="false" @change="initBusinessType2">
              <el-option
                v-for="(list, index) of businessType1Option"
                :key="index"
                :value="list.businessType"
                :label="list.businessTypeName"
              />
            </el-select> -->
          </el-form-item>
          <el-form-item prop="businessType2" label="二级业务类型">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="SECOND_LEVEL_BUSINESS_TYPE"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.businessType2"
              filterable
              multiple
            ></CustomDictSelect>
            <!-- <el-select v-model="formData.businessType2" filterable clearable @change="businessTypeTwoChange">
              <el-option
                v-for="(list, index) of businessType2Option"
                :key="index"
                :value="list.businessTypeTwo"
                :label="list.businessTypeTwoName"
              />
            </el-select> -->
          </el-form-item>
          <el-form-item key="repairsReason" prop="repairsReason" label="报修原因">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="REPAIR_REASON"
              bind-name="dictName"
              bind-value="dictCode"
              filterable
              :echo-value.sync="formData.repairsReason"
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="complaintCause" label="投诉原因">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="COMPLAINTS_REASON"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.complaintCause"
              filterable
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="complaintObject" label="被投诉对象">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="OBJECT_OF_COMPLAINT"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.complaintObject"
              filterable
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="customerDisapprovalCause" label="顾客不认可原因">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="CUSTOMER_DISAGREE_REASON"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.customerDisapprovalCause"
              filterable
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="complaintType" label="投诉类型">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="COMPLAINTS_TYPE"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.complaintType"
              filterable
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="serviceFeeType" label="服务费类型">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="SERVICE_FEE_TYPE"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.serviceFeeType"
              filterable
            ></CustomDictSelect>
          </el-form-item>
          <!-- <el-form-item prop="feeType" label="费用类型">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="EXPENSE_TYPE"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.feeType"
              filterable
            ></CustomDictSelect>
          </el-form-item> -->
          <el-form-item prop="compensationCause" label="赔付原因">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="COMPENSATION_REASON"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.compensationCause"
              filterable
            ></CustomDictSelect>
          </el-form-item>
          <!-- <el-form-item prop="invoiceSubBusiness" label="发票子业务">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="INVOICE_SUB_SERVICE"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.invoiceSubBusiness"
              filterable
            ></CustomDictSelect>
          </el-form-item> -->
          <el-form-item prop="productProblem" label="产品问题">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="PRODUCT_PROBLEM"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.productProblem"
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="transportationLossType" label="运损类型">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="TRANSPORT_DAMAGE_TYPE"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.transportationLossType"
              filterable
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="productType" label="产品类型">
            <el-select v-model="formData.productType" filterable clearable @change="productTypelChange">
              <el-option
                v-for="(list, index) in productTypeOption"
                :key="index"
                :value="list.dictCode"
                :label="list.dictName"
              />
            </el-select>
          </el-form-item>
          <!-- <el-form-item prop="functionalSpace" label="功能空间">
            <el-select v-model="formData.functionalSpace" filterable clearable @change="functionalSpaceChange">
              <el-option
                v-for="(list, index) in functionalSpaceOption"
                :key="index"
                :value="list.dictCode"
                :label="list.dictName"
              />
            </el-select>
          </el-form-item> -->
          <!-- <el-form-item prop="productCategory" label="产品品类">
            <el-select v-model="formData.productCategory" filterable clearable>
              <el-option
                v-for="(list, index) in productCategoryOption"
                :key="index"
                :value="list.dictCode"
                :label="list.dictName"
              />
            </el-select>
          </el-form-item> -->
          <el-form-item prop="urgencyDegree" label="紧急程度">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="URGENCY_DEGREE"
              bind-name="dictName"
              bind-value="dictCode"
              collapse-tags
              multiple
              :echo-value.sync="formData.urgencyDegree"
              filterable
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="urgencyCause" label="紧急原因">
            <el-input v-model="formData.urgencyCause" placeholder="请输入" clearable />
          </el-form-item>
          <el-form-item prop="onlinePlatformCode" label="电商平台">
            <el-select v-model="formData.onlinePlatformCode" filterable clearable @change="onlinePlatformChange">
              <el-option
                v-for="(list, index) in onlinePlatformOption"
                :key="index"
                :value="list.code"
                :label="list.name"
              />
            </el-select>
          </el-form-item>
          <el-form-item prop="onlineShopCode" label="电商店铺">
            <el-select v-model="formData.onlineShopCode" filterable clearable>
              <el-option
                v-for="(list, index) in onlineShopOption"
                :key="index"
                :value="list.code"
                :label="list.name"
              />
            </el-select>
          </el-form-item>
          <el-form-item prop="deliveryMethod" label="配送方式">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="CC_DELIVERY_TYPE"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.deliveryMethod"

              filterable
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="deliveryTime" label="预约送货时间">
            <el-date-picker
              v-model="formData.deliveryTime"
              type="daterange"
              placeholder="选择预约送货时间"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              clearable
            />
          </el-form-item>
          <el-form-item prop="isOverdue" label="是否超期">
            <el-select v-model="formData.isOverdue" clearable>
              <el-option
                v-for="(r,i) in yesOrNoOption"
                :key="i"
                :value="r.value"
                :label="r.label"
              />
            </el-select>
          </el-form-item>
          <el-form-item prop="overdueReason" label="超期原因">
            <CustomDictSelect
              placeholder="超期原因"
              dict-type-code="OVERDUE_REASON"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.overdueReason"
              filterable
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="isTimeoutOrder" label="超时工单">
            <el-select v-model="formData.isTimeoutOrder" filterable clearable placeholder="请选择">
              <el-option
                v-for="(r,i) in yesOrNoOption"
                :key="i"
                :value="r.value"
                :label="r.label"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item prop="isTimeout" label="是否超时">
            <el-select v-model="formData.isTimeout" clearable>
              <el-option
                v-for="(r, i) in yesOrNoOption"
                :key="i"
                :value="r.value"
                :label="r.label"
              />
            </el-select>
          </el-form-item>
          <el-form-item prop="createBy" label="创建人">
            <SearchSelectPicker
              url="/call-center/api/v1/staffInfo/page"
              placeholder="请选择"
              lable-name="staffName"
              value-name="accountNo"
              :value.sync="formData.createBy"
            ></SearchSelectPicker>
          </el-form-item>
          <!-- <el-form-item prop="createByPlatformNo" label="创建人工号">
            <el-input v-model.trim="formData.createByPlatformNo" placeholder="请输入创建人工号" clearable />
          </el-form-item> -->
          <el-form-item prop="createByGroupNo" label="创建人业务组">
            <el-select v-model="formData.createByGroupNo" filterable clearable placeholder="请选择业务组">
              <el-option
                v-for="item in businessOptions"
                :key="item.id"
                :label="item.groupName"
                :value="item.groupNo"
              />
            </el-select>
          </el-form-item>
          <el-form-item prop="handleScheme" label="处理方案">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="PROCESS_METHOD"
              bind-name="dictName"
              bind-value="dictCode"
              collapse-tags
              multiple
              filterable
              :echo-value.sync="formData.handleScheme"
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="paymentMode" label="支付方式">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="PAYMENT_MODE"
              bind-name="dictName"
              bind-value="dictCode"
              collapse-tags
              multiple
              filterable
              :echo-value.sync="formData.paymentMode"
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="deliveryNeed" label="送装需求">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="DELIVERY_INSTALL_DEMAND"
              bind-name="dictName"
              bind-value="dictCode"
              filterable
              :echo-value.sync="formData.deliveryNeed"
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="returnsCause" label="退/换货原因">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="RETURN_REPLACEMENT_REASON"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.returnsCause"
              filterable
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="orderTime" label="下单时间">
            <el-date-picker
              v-model="formData.orderTime"
              type="daterange"
              placeholder="选择下单时间"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              clearable
            />
          </el-form-item>
          <el-form-item prop="timeoutReason" label="处理时效">
            <CustomDictSelect
              dict-type-code="TIMEOUT_REASON"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.timeoutReason"
              filterable
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="patchCode" label="补件单号">
            <el-input v-model="formData.patchCode" clearable placeholder="补件单号" :maxlength="100" />
          </el-form-item>
          <el-form-item prop="isTwoCheckComputation" label="核算二次费用">
            <el-select v-model="formData.isTwoCheckComputation" clearable>
              <el-option
                v-for="(r,i) in yesOrNoOption"
                :key="i"
                :value="r.value"
                :label="r.label"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="bpmDeptCode" label="业务部门">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="RESPONSIBLE_DEPARTMENT"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.bpmDeptCode"
            ></CustomDictSelect>
          </el-form-item>
          <!-- <el-form-item prop="isCare" label="是否关怀">
            <el-select v-model="formData.isCare" clearable placeholder="请选择是否关怀">
              <el-option
                v-for="(r,i) in yesOrNoOption"
                :key="i"
                :value="r.value"
                :label="r.label"
              ></el-option>
            </el-select>
          </el-form-item> -->
          <el-form-item prop="dispatchDutyDepts" label="派单责任部门">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="RESPONSIBLE_DEPARTMENT"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.dispatchDutyDepts"
              multiple
              collapse-tags
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="dispatchReceiver" label="派单接收人">
            <el-input v-model="formData.dispatchReceiver" clearable placeholder="派单接收人" :maxlength="100" />
          </el-form-item>
          <el-form-item prop="ccDutyDepts" label="抄送责任部门">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="RESPONSIBLE_DEPARTMENT"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.ccDutyDepts"
              multiple
              collapse-tags
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="ccReceiver" label="抄送接收人">
            <el-input v-model="formData.ccReceiver" clearable placeholder="抄送接收人" :maxlength="100" />
          </el-form-item>

          <el-form-item prop="dispatchOffice" label="派单办事处">
            <SearchSelectPicker
              url="/call-center/api/v1/mscInfo/office/ref/page"
              placeholder="请选择"
              lable-name="name"
              value-name="code"
              method="get"
              :value.sync="formData.dispatchOffice"
              :lable.sync="formData.dispatchOfficeName"
            ></SearchSelectPicker>
          </el-form-item>
          <el-form-item prop="ccOffice" label="抄送办事处">
            <SearchSelectPicker
              url="/call-center/api/v1/mscInfo/office/ref/page"
              placeholder="请选择"
              lable-name="name"
              value-name="code"
              method="get"
              :value.sync="formData.ccOffice"
              :lable.sync="formData.ccOfficeName"
            ></SearchSelectPicker>
          </el-form-item>
          <el-form-item prop="dispatchDisCode" label="派单经销商">
            <!-- <SearchSelectPicker
              url="/call-center/api/v1/mscInfo/dealer/ref/page"
              method="get"
              placeholder="请选择"
              :params="{query:{officeCode:formData.dispatchOffice},type:0}"
              lable-name="name"
              value-name="code"
              custom-name="codeOrName"
              :parent-id="formData.dispatchOffice"
              :value.sync="formData.dispatchDisCode"
              :lable.sync="formData.dispatchDisName"
              :current-id.sync="formData.dispatchDisId"
              clearable
            ></SearchSelectPicker> -->
            <SearchSelectPicker
              url="/call-center/api/v1/dealerSelector/page"
              method="post"
              placeholder="请选择"
              :params="{query:{agencyCode:{value: formData.dispatchOffice, operator: '='}},type:0}"
              lable-name="name"
              value-name="code"
              :parent-id="formData.dispatchOffice"
              :value.sync="formData.dispatchDisCode"
              :lable.sync="formData.dispatchDisName"
              :current-id.sync="formData.dispatchDisId"
              clearable
            ></SearchSelectPicker>
          </el-form-item>
          <el-form-item prop="ccDisCode" label="抄送经销商">
            <!-- <SearchSelectPicker
              url="/call-center/api/v1/mscInfo/dealer/ref/page"
              method="get"
              placeholder="请选择"
              :params="{query:{officeCode:formData.ccOffice},type:0}"
              lable-name="name"
              value-name="code"
              custom-name="codeOrName"
              :parent-id="formData.ccOffice"
              :value.sync="formData.ccDisCode"
              :lable.sync="formData.ccDisName"
              :current-id.sync="formData.ccDisId"
              clearable
            ></SearchSelectPicker> -->
            <SearchSelectPicker
              url="/call-center/api/v1/dealerSelector/page"
              method="post"
              placeholder="请选择"
              :params="{query:{agencyCode:{value: formData.ccOffice, operator: '='}},type:0}"
              lable-name="name"
              value-name="code"
              :parent-id="formData.ccOffice"
              :value.sync="formData.ccDisCode"
              :lable.sync="formData.ccDisName"
              :current-id.sync="formData.ccDisId"
              clearable
            ></SearchSelectPicker>
          </el-form-item>
          <el-form-item prop="dispatchShopCode" label="派单门店">
            <!-- <SearchSelectPicker
              :url="'/call-center/api/v1/mscInfo/shop/list/' + formData.dispatchDisId"
              placeholder="请选择"
              lable-name="name"
              value-name="code"
              method="get"
              :must-pid="true"
              :parent-id="formData.dispatchDisId"
              :value.sync="formData.dispatchShopCode"
              :lable.sync="formData.dispatchShopName"
            ></SearchSelectPicker> -->
            <SearchSelectPicker
              url="/call-center/api/v1/shopSelector/page"
              placeholder="请选择"
              lable-name="name"
              value-name="code"
              method="post"
              :params="{query:{customerId:{value: formData.dispatchDisId, operator: '='}},type:0}"
              :must-pid="true"
              :parent-id="formData.dispatchDisId"
              :value.sync="formData.dispatchShopCode"
              :lable.sync="formData.dispatchShopName"
              clearable
            ></SearchSelectPicker>
          </el-form-item>
          <el-form-item prop="ccShopCode" label="抄送门店">
            <!-- <SearchSelectPicker
              :url="'/call-center/api/v1/mscInfo/shop/list/' + formData.ccDisId"
              placeholder="请选择"
              lable-name="name"
              value-name="code"
              method="get"
              :must-pid="true"
              :parent-id="formData.ccDisId"
              :value.sync="formData.ccShopCode"
              :lable.sync="formData.ccShopName"
            ></SearchSelectPicker> -->
            <SearchSelectPicker
              url="/call-center/api/v1/shopSelector/page"
              placeholder="请选择"
              lable-name="name"
              value-name="code"
              method="post"
              :params="{query:{customerId:{value: formData.ccDisId, operator: '='}},type:0}"
              :must-pid="true"
              :parent-id="formData.ccDisId"
              :value.sync="formData.ccShopCode"
              :lable.sync="formData.ccShopName"
              clearable
            ></SearchSelectPicker>
          </el-form-item>
          <!-- <el-form-item prop="afterSalesCall" label="售后联系人电话" label-width="110px">
            <el-input v-model.trim="formData.afterSalesCall" clearable placeholder="售后联系人电话" />
          </el-form-item> -->
          <el-form-item prop="dispatchOperationMode" label="派单组织">
            <el-select v-model="formData.dispatchOperationMode" clearable placeholder="请选择">
              <el-option
                v-for="(r,i) in orgOption"
                :key="i"
                :value="r.value"
                :label="r.label"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="ccOperationMode" label="抄送组织">
            <el-select v-model="formData.ccOperationMode" clearable placeholder="请选择">
              <el-option
                v-for="(r,i) in orgOption"
                :key="i"
                :value="r.value"
                :label="r.label"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="createTime" label="创建时间">
            <el-date-picker
              v-model="formData.createTime"
              type="daterange"
              opt
              operator=">"
              :limite="new Date()"
              clearable
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
            />
          </el-form-item>
          <el-form-item
            prop="dispatchTime"
            label="派单时间"
            :span="24 / 5 * 2"
          >
            <el-date-picker
              v-model="formData.dispatchTime"
              type="datetimerange"
              opt
              clearable
              format="yyyy-MM-dd HH:mm:ss"
              value-format="yyyy-MM-dd HH:mm:ss"
              @focus="handleDateTimeRageFocus('dispatchTime')"
            />
          </el-form-item>
          <el-form-item
            prop="finishTime"
            label="结案时间"
            :span="24 / 5 * 2"
          >
            <el-date-picker
              v-model="formData.finishTime"
              type="daterange"
              opt
              clearable
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
            />
          </el-form-item>
          <el-form-item
            prop="bookingServiceTime"
            label="预约送装服务时间"
            :span="24 / 5 * 2"
          >
            <el-date-picker
              v-model="formData.bookingServiceTime"
              type="datetimerange"
              placeholder="选择预约送装服务时间"
              value-format="yyyy-MM-dd HH:mm:ss"
              clearable
            />
          </el-form-item>
          <el-form-item
            prop="processingDeadline"
            label="处理截止时间"
            :span="24 / 5 * 2"
          >
            <el-date-picker
              v-model="formData.processingDeadline"
              type="datetimerange"
              clearable
              opt
              format="yyyy-MM-dd HH:mm:ss"
              value-format="yyyy-MM-dd HH:mm:ss"
              @focus="handleDateTimeRageFocus('processingDeadline')"
            />
          </el-form-item>
          <!-- <el-form-item prop="sourceSystem" label="来源系统">
            <CustomDictSelect
              placeholder="来源系统"
              dict-type-code="SOURCE_SYSTEM"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.sourceSystem"
              filterable
            ></CustomDictSelect>
          </el-form-item> -->

          <el-form-item prop="officeCode" label="办事处">
            <SearchSelectPicker
              url="/call-center/api/v1/mscInfo/office/ref/page"
              placeholder="请选择办事处"
              lable-name="name"
              value-name="code"
              method="get"
              :value.sync="formData.officeCode"
              @selectChange="officeChange"
            ></SearchSelectPicker>
          </el-form-item>
          <el-form-item prop="disCode" label="经销商">
            <SearchSelectPicker
              url="/call-center/api/v1/dealerSelector/page"
              method="post"
              placeholder="请选择经销商"
              :params="{query:{agencyCode:{value: formData.officeCode, operator: '='}},type:0}"
              lable-name="name"
              value-name="code"
              custom-name="name"
              :parent-id="formData.officeCode"
              :value.sync="formData.disCode"
              :disabled="!formData.officeCode"
              clearable
            ></SearchSelectPicker>
            <!-- <SearchSelectPicker
              url="/call-center/api/v1/mscInfo/dealer/ref/page"
              method="get"
              placeholder="请选择经销商"
              :params="{query:{officeCode:formData.officeCode},type:0}"
              lable-name="name"
              value-name="code"
              custom-name="codeOrName"
              :parent-id="formData.officeCode"
              :value.sync="formData.disCode"
              :disabled="!formData.officeCode"
              clearable
            ></SearchSelectPicker> -->
          </el-form-item>
          <!-- :current-id.sync="formData.disId" -->

          <el-form-item prop="customerApplyStatus" label="商家回复">
            <CustomDictSelect
              placeholder="商家回复"
              dict-type-code="CUSTOMER_APPLY_STATUS"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.customerApplyStatus"
              filterable
            ></CustomDictSelect>
          </el-form-item>

          <el-form-item align="right" label-width="0px" show more style="white-space: nowrap;">
            <Button @click="resetSearch('formOrder')">重置</Button>
            <Button type="primary" enter @click="querySearch('formOrder')">查询</Button>
          </el-form-item>
        </el-form>
      </FormContainer>
      <div style="text-align:right">
        <ChangeHandler v-if="!query" :selected-arry="selectedArry" @on-change-success="querySearch('formOrder', '', 'onPage')"></ChangeHandler>
        <ExportPane v-if="!query" :data-source="selectedArry" :other-raw="otherParamRows" :table-config="tableConfig" :fields="exportFields" :query-data-fun="queryDataFun" filename="处理工单">导出</ExportPane>
        <Button type="primary" @click="$refs.table.showSetting = true">设置表格样式</Button>
      </div>
      <table-box
        ref="table"
        no-request
        :table-config="tableConfig"
        :other-filters="disposeOrderParams"
        :other-raw="otherParamRows"
        show-index
        @selection-change="selectionChange"
      >
        <el-table-column v-if="!query" slot="before" align="center" type="selection" width="50" />
      </table-box>
    </ContentWrap>
  </div>
</template>
<script>
import ContentWrap from '@/components/ContentWrap'
import Button from '@/components/Button'
import FormContainer from '@/components/FormContainer'
import SearchSelectPicker from '@/components/SearchSelectPicker'
import CustomDictSelect from '@/components/CustomDictSelect'
import { ArrayFormat } from '@/utils/params-format'
import { deepCopy, isEmpty, pageRequsetBody, json2FormData, parseTime } from '@/utils/'
import { getDictByType } from '@/api/dataDict'
import { searchBusinessByChannel, searchBusinessTwoByChannel } from '@/api/ChannelBusinessRel'
import { getStoreInfoB2CECO, getPlatformInfoB2CECO } from '@/api/mscInfo'
import ExportPane from '@/components/ExportPane'
import { PSCMap } from '../createOrder/productSpaceCategory' // 产品=>功能空间=>产品分类映射数据
import { TCCMap } from '../createOrder/businessType2ComplaintCause' // 二级业务类型=>投诉原因映射数据
import { workOrderExport } from '@/api/workOrder'
import ChangeHandler from './components/ChangeHandler'
import { getBusinessAll } from '@/api/business'
import SmsAndCallOut from '@/components/SmsAndCallOut'

export default {
  name: 'DisposeOrder',
  components: {
    ContentWrap,
    Button,
    FormContainer,
    SearchSelectPicker,
    CustomDictSelect,
    ExportPane,
    ChangeHandler
  },
  props: {
    query: {
      type: [Boolean],
      default: false
    }
  },
  data() {
    // 验证创建时间
    // const validatorCT = (r, v, c) => {
    //   if (v && v instanceof Array && v.length === 2) {
    //     c()
    //   } else {
    //     c(new Error('请选择创建时间'))
    //   }
    // }
    return {
      businessOptions: [], // 业务组
      // 选择项
      selectedArry: [],
      deptRelAll: [],
      businessType1Option: [], // 业务类型1下拉数据
      businessType2Option: [], // 业务类型2下拉数据
      productTypeOption: [], // 产品类型下拉数据
      functionalSpaceOption: [], // 当前可选功能空间下拉数据
      functionalSpaceStore: [], // 全部功能空间
      productCategoryOption: [], // 当前可选产品品类下拉数据
      productCategoryStore: [], // 全部产品品类
      complaintCauseOption: [], // 当前投诉原因下拉数据
      complaintCauseStore: [], // 所有投诉原因数据
      onlinePlatformOption: [], // 电商平台下拉数据
      onlineShopOption: [], // 电商店铺下拉数据
      deleteOrderStateId: '',
      yesOrNoOption: [
        { value: 1, label: '是' },
        { value: 0, label: '否' }
      ],
      orgOption: [
        { value: '01', label: '办事处' },
        { value: '02', label: '经销商' },
        { value: '03', label: '责任部门' }
      ],
      shopCallTel: [],
      formData: {
        nextHandler: [], // 处理人账号
        nextHandlerName: [], // 处理人姓名
        nextHandlerPlatformNo: '', // 处理人工号
        handlerGroupNo: '', // 处理人业务组
        handlerPostCode: '', // 处理人岗位
        contactName: '', // 联系人
        contactPhone: '', // 联系电话
        nickname: '', // 顾客id
        orderCode: '', // 平台订单号
        ecOrderNumber: '', // 电商订单编号
        workOrderCode: '', // 工单编号
        workOrderState: [], // 工单状态
        dispatchReceiveState: '', // 派送接收状态
        ccReceiveState: '', // 抄送接收状态
        processRate: [], // 维修进度
        buyChannel: '', // 购买渠道
        channelType: '', // 联系渠道
        businessType1: '', // 业务类型1
        businessType2: [], // 业务类型2
        repairsReason: '',
        complaintCause: '', // 投诉原因
        complaintObject: '', // 被投诉对象
        customerDisapprovalCause: '', // 顾客不认可原因
        complaintType: '', // 投诉类型
        serviceFeeType: '', // 服务费类型
        feeType: '', // 费用类型
        compensationCause: '', // 赔付原因
        invoiceSubBusiness: '', // 发票子业务
        productProblem: '', // 产品问题
        transportationLossType: '', // 运损类型
        productType: '', // 产品类型
        functionalSpace: '', // 功能空间
        productCategory: '', // 产品品类
        urgencyDegree: [], // 紧急程度
        urgencyCause: '', // 紧急原因
        onlinePlatformCode: '', // 电商平台Code
        onlinePlatformName: '', // 电商平台
        onlineShopCode: '', // 电商店铺Code
        onlineShopName: '', // 电商店铺
        deliveryMethod: '', // 配送方式
        deliveryTime: [], // 预约送货时间
        isOverdue: '', // 是否超期
        overdueReason: '', // 超期原因
        isTimeoutOrder: '', // 是否超时工单
        isTimeout: '', // 是否超时
        createBy: '', // 创建人
        createByPlatformNo: '', // 创建人工号
        createByGroupNo: '', // 创建人业务组
        handleScheme: [], // 处理方案
        paymentMode: [], // 支付方式
        deliveryNeed: '', // 送装需求
        bookingServiceTime: [], // 送装预约时间
        returnsCause: '', // 退换货原因
        orderTime: [], // 下单时间
        timeoutReason: '', // 处理时效
        patchCode: '', // 补件单号
        isTwoCheckComputation: '', // 核算二次费用
        bpmDeptCode: '', // 责任部门
        isCare: '', // 是否关怀

        dispatchDutyDepts: [], // 派单责任部门（paramRow）
        dispatchReceiver: '', // 派单接收人（paramRow）
        ccDutyDepts: [], // 抄送责任部门（paramRow）
        ccReceiver: '', // 抄送接收人（paramRow）
        dispatchOffice: '', // 派单办事处Code（paramRow）
        dispatchOfficeName: '', // 派单办事处
        ccOffice: '', // 抄送办事处Code（paramRow）
        ccOfficeName: '', // 抄送办事处
        dispatchDisCode: '', // 派单经销商Code（paramRow）
        dispatchDisName: '', // 派单经销商
        ccDisCode: '', // 抄送经销商Code（paramRow）
        ccDisName: '', // 抄送经销商
        dispatchShopCode: '', // 派单门店Code（paramRow）
        dispatchShopName: '', // 派单门店
        ccShopCode: '', // 抄送门店Code（paramRow）
        ccShopName: '', // 抄送门店
        dispatchOperationMode: '', // 派单组织（paramRow）
        ccOperationMode: '', // 抄送组织（paramRow）

        afterSalesCall: '', // 售后联系人电话

        createTime: [], // 创建时间
        dispatchTime: [], // 派单时间
        finishTime: [], // 结案时间
        processingDeadline: [], // 截止时间

        dispatchDisId: '', // 派送经销商Id
        ccDisId: '', // 抄送经销商Id
        sourceSystem: '', // 来源系统
        officeCode: '', // 办事处编码
        disCode: '', // 经销商编码
        customerApplyStatus: '' // 商家回复状态
      },
      formRules: {
        // createTime: [{ required: true, validator: validatorCT, trigger: 'change' }]
      },
      disposeOrderParams: [], // 表格查询filter条件
      otherParamRows: {}, // 表格查询paramRow
      tableConfig: {
        interfacePath: '/call-center/api/v2/workOrderRecord/page',
        pageFlag: true,
        hideFuncBar: false,
        totalFlag: true,
        tabIndex: 0,
        // sort: 'dispatchTime',
        // order: 'desc',
        pageSize: 20,
        // 表格字段动态配置
        setting: [
          {
            prop: 'workOrderCode',
            label: '工单编号',
            width: 150,
            // isButton: true,
            // className: 'table-handelclick-text',
            // clickFun: this.columnClickHandle,
            // 当工单紧急程度为【紧急】或【非常紧急】，
            // 是否超时为【是】，是否超期为【是】，
            // 工单状态为处理中时，工单置顶并标红
            render: (h, row) => {
              const { urgencyDegree, isTimeout, workOrderState } = row
              const shouldRedColor = ([2, 3, '2', '3'].includes(urgencyDegree) || [1, '1'].includes(isTimeout)) && [2, '2'].includes(workOrderState)
              /** || [1, '1'].includes(isOverdue)**/
              const style = {}
              if (shouldRedColor) {
                style.color = 'red !important'
              }
              return h('span', {
                style,
                class: 'table-handelclick-text',
                on: {
                  click: e => { e.preventDefault(); e.stopPropagation(); this.columnClickHandle(row) }
                }
              }, row.workOrderCode)
            }
          },
          {
            prop: 'contactName',
            label: '联系人',
            width: 90
          },
          {
            prop: 'contactPhone',
            label: '联系电话',
            width: 150,
            render: (h, row) => {
              return h(SmsAndCallOut, {
                props: {
                  value: row.contactPhone,
                  allowInput: false
                }
              })
            }
          },
          {
            prop: 'nickname',
            label: '顾客ID',
            width: 100
          },
          {
            prop: 'businessType1Name',
            label: '一级业务类型',
            width: 140
          },
          {
            prop: 'businessType2Name',
            label: '二级业务类型',
            width: 140
          },
          {
            prop: 'repairsReason',
            label: '报修原因',
            width: 140,
            type: 'select',
            propEnum: {
              appCode: 'call-center',
              domainCode: 'marketing',
              dictTypeCode: 'REPAIR_REASON'
            }
          },
          {
            prop: 'workOrderState',
            label: '工单状态',
            width: 100,
            type: 'select',
            propEnum: {
              appCode: 'call-center',
              domainCode: 'marketing',
              dictTypeCode: 'WORK_ORDER_STATUS'
            }
          },
          {
            prop: 'processRate',
            label: '维修进度',
            width: 100,
            type: 'select',
            propEnum: {
              appCode: 'call-center',
              domainCode: 'marketing',
              dictTypeCode: 'PROCESS_RATE'
            }
          },
          {
            prop: 'handleScheme',
            label: '处理方案',
            width: 100,
            type: 'select',
            propEnum: {
              appCode: 'call-center',
              domainCode: 'marketing',
              dictTypeCode: 'PROCESS_METHOD'
            }
          },
          {
            prop: 'processingDeadline',
            label: '处理截止时间',
            width: 140,
            type: 'date'
          },
          {
            prop: 'nextHandlerName',
            label: '处理人',
            width: 160,
            formatData: v => {
              // if (!v.nextHandlerName) return '--'
              // let str = `${v.nextHandlerName}(${v.nextHandler})`
              // if (v.nextHandlerPlatformNo) {
              //   str += ` - ${v.nextHandlerPlatformNo}`
              // }
              // return str
              return v.handlerDTOList instanceof Array ? v.handlerDTOList.map(e => `${e.handlerName}(${e.handler})`).join(',') : ''
            }
          },
          {
            prop: 'officeName',
            label: '办事处',
            width: 100
          },
          {
            prop: 'disName',
            label: '经销商',
            width: 100
          },
          {
            prop: 'shopName',
            label: '门店'
          },
          {
            prop: 'customerApplyStatus',
            label: '商家回复',
            width: 100,
            type: 'select',
            propEnum: {
              appCode: 'call-center',
              domainCode: 'marketing',
              dictTypeCode: 'CUSTOMER_APPLY_STATUS'
            }
          },
          {
            prop: 'bpmDeptName',
            label: '业务部门',
            width: 100
          },
          /* {
            prop: 'receiver',
            label: '接收人',
            width: 100
          }, */
          {
            prop: 'callContent',
            width: 140,
            label: '来电明细'
          },
          {
            prop: 'customerServiceOpinion',
            width: 140,
            label: '客服意见'
          },
          {
            prop: 'dispatchTime',
            label: '派单时间',
            width: 140,
            type: 'date'
          },
          {
            prop: 'createrName',
            label: '创建人',
            width: 120,
            formatData: v => {
              if (!v.createrName) return '--'
              let str = `${v.createrName}(${v.createBy})`
              if (v.createByPlatformNo) {
                str += ` - ${v.createByPlatformNo}`
              }
              return str
            }
          },
          {
            prop: 'createTime',
            label: '创建时间',
            width: 140,
            type: 'date'
          },
          {
            prop: 'finishTime',
            label: '结案时间',
            width: 140,
            type: 'date'
          },
          {
            prop: 'sourceSystem',
            label: '来源系统',
            width: 140,
            propEnum: {
              appCode: 'call-center',
              domainCode: 'marketing',
              dictTypeCode: 'SOURCE_SYSTEM'
            }
          }
        ]
      },
      // 导出工单字段 TODO:字段待核对
      exportFields: {
        workOrderCode: '工单编号',	createTime: '创建时间', nextHandlerName: '处理人',
        handlerGroupNoName: '处理人业务组', nickname: '顾客ID',	contactName: '联系人',
        contactPhone: '联系电话',
        channelType: {
          label: '联系渠道',
          propEnum: {
            dictTypeCode: 'CHANNEL_TYPE'
          }
        },	callContent: '来电明细',	customerServiceOpinion: '客服意见',
        businessType1Name: '一级业务类型',	businessType2Name: '二级业务类型', repairsReason: {
          label: '报修原因',
          propEnum: {
            dictTypeCode: 'REPAIR_REASON'
          }
        }, complaintCause: {
          label: '投诉原因',
          propEnum: {
            dictTypeCode: 'COMPLAINTS_REASON'
          }
        }, complaintType: {
          label: '投诉类型',
          propEnum: {
            dictTypeCode: 'COMPLAINTS_TYPE'
          }
        }, complaintObject: {
          label: '被投诉对象',
          propEnum: {
            dictTypeCode: 'OBJECT_OF_COMPLAINT'
          }
        }, workOrderState: '工单状态',
        finishTime: '完结时间',	processRate: '维修进度', subsidyAmount: '补贴金额',
        subsidyReason: {
          label: '补贴原因',
          propEnum: {
            dictTypeCode: 'SUBSIDY_REASON'
          }
        },	urgencyDegree: {
          label: '紧急程度',
          propEnum: {
            dictTypeCode: 'URGENCY_DEGREE'
          }
        },
        urgencyCause: '紧急原因',	functionalSpace: {
          label: '功能空间', //    PRODUCT_CATEGORY
          propEnum: {
            dictTypeCode: 'FUNCTIONAL_SPACE'
          }
        }, productCategory: {
          label: '产品品类', //    PRODUCT_CATEGORY
          propEnum: {
            dictTypeCode: 'PRODUCT_CATEGORY'
          }
        },	productType: {
          label: '产品类型',
          propEnum: {
            dictTypeCode: 'PRODUCT_TYPE'
          }
        }, productProblem: {
          label: '产品问题',
          propEnum: {
            dictTypeCode: 'PRODUCT_PROBLEM'
          }
        },	orderTime: '下单时间',	deliveryTime: '预约送货时间',
        deliveryMethod: {
          label: '配送方式',
          propEnum: {
            dictTypeCode: 'CC_DELIVERY_TYPE'
          }
        },
        deliveryNeed: {
          label: '送装需求',
          propEnum: {
            dictTypeCode: 'DELIVERY_INSTALL_DEMAND'
          }
        },
        onlinePlatformName: '电商平台',	onlineShopName: '电商店铺',	orderCode: '平台订单号', ecOrderNumber: '电商单号',
        officeName: '办事处',	disName: '经销商', customerApplyStatus: {
          label: '商家回复',
          propEnum: {
            dictTypeCode: 'CUSTOMER_APPLY_STATUS'
          }
        },	shopName: '门店',
        createrName: '创建人',
        createByGroupNoName: '创建人业务组',
        handleScheme: {
          label: '处理方案',
          propEnum: {
            dictTypeCode: 'PRODUCT_PROBLEM'
          }
        },
        patchCode: '补件单号',
        isTimeout: {
          label: '是否超时',
          formatData: v => {
            let t = ''
            for (const item of this.yesOrNoOption) {
              if (item.value === v.isTimeout) {
                t = item.label
                break
              }
            }
            return t
          }
        },
        isTimeoutTime: '超时时间',
        unseasonalTime: '处理不及时时间',
        isTimeoutOrder: {
          label: '超时工单',
          formatData: v => {
            let t = ''
            for (const item of this.yesOrNoOption) {
              if (Number(item.value) === v.isTimeoutOrder) {
                t = item.label
                break
              }
            }
            return t
          }
        },
        overtimeReason: {
          label: '超时原因',
          propEnum: {
            dictTypeCode: 'OVER_TIME_REASON'
          }
        },
        isOverdue: {
          label: '是否超期',
          formatData: v => {
            let t = ''
            for (const item of this.yesOrNoOption) {
              if (item.value === v.isOverdue) {
                t = item.label
                break
              }
            }
            return t
          }
        },	overdueReason: {
          label: '超期原因',
          propEnum: {
            dictTypeCode: 'OVERDUE_REASON'
          }
        },	processingDeadline: '处理截止时间', 	dispatchTime: '派单时间', dispatchPerson: '派单人',
        timeoutReason: {
          label: '处理时效',
          propEnum: {
            dictTypeCode: 'TIMEOUT_REASON'
          }
        },
        isTwoCheckComputation: {
          label: '核算二次费用',
          formatData: v => {
            if (v.isTwoCheckComputation !== undefined && v.isTwoCheckComputation !== null && v.isTwoCheckComputation.toString() === '1') {
              return '是'
            } else {
              return '否'
            }
          }
        },
        // lastSaveTime: '最后保存时间',
        // saveContent: '工单流水记录',
        afterSalesCall: '售后联系人电话',
        bpmDeptName: '业务部门', detailAddress: '详细地址',
        productCode: {
          label: '产品编码',
          formatData: row => {
            this.productInfoDTOListSort(row)
            return row.__productCode
          }
        },
        productName: {
          label: '产品名称',
          formatData: row => {
            this.productInfoDTOListSort(row)
            return row.__productName
          }
        },
        productMode: {
          label: '产品型号',
          formatData: row => {
            this.productInfoDTOListSort(row)
            return row.__productCategory
          }
        },
        returnsCause: {
          label: '退/换货原因',
          propEnum: {
            dictTypeCode: 'RETURN_REPLACEMENT_REASON'
          }
        },
        invalidFinish: {
          label: '无效完结',
          formatData: row => {
            if (row.invalidFinish === undefined || row.invalidFinish === null || row.invalidFinish === '') {
              return ''
            }
            // 1无效完结 0有效完结
            return [0, '0'].includes(row.invalidFinish) ? '否' : '是'
          }
        }
      }
    }
  },
  created() {
    if (!this.query) {
      const { account, userName } = this.$store.state.user.user
      account ? this.formData.nextHandler = [account] : this.formData.nextHandler = []
      userName ? this.formData.nextHandlerName = [userName] : this.formData.nextHandlerName = []
    }
    // 获取业务组
    this.initBusinessOption()
  },
  // keep-alive 周期
  activated() {
    if (this.$refs.table.tableData.length) {
      this.$nextTick(() => {
        this.$refs.table.initTableData('onPage')
      })
    }
  },
  mounted() {
    this.getPlatformList() // 初始化电商平台
    this.getDataDict({ type: 'complaintCause', ditctType: 'COMPLAINTS_REASON' }) // 投诉原因
    this.getDataDict({ type: 'productType', ditctType: 'PRODUCT_TYPE' })// 产品类型
    this.getDataDict({ type: 'functionalSpace', ditctType: 'FUNCTIONAL_SPACE' })// 功能空间
    this.getDataDict({ type: 'productCategory', ditctType: 'PRODUCT_CATEGORY' })// 产品品类
  },
  methods: {
    getCode(v) {
      let total = 0
      for (let i = 0; i < (v || '').length; i++) {
        total = total + v[i].charCodeAt()
      }
      return total
    },
    // 产品信息排序
    productInfoDTOListSort(row) {
      if (row.isSort) {
        return
      }
      row.__productCode = ''
      row.__productName = ''
      row.__productCategory = ''
      const t = row.productInfoDTOList
      if (!t || !(t instanceof Array)) {
        row.isSort = true
        return ''
      }
      t.sort((a, b) => {
        const pa = this.getCode(a.productCode || '0')
        const pb = this.getCode(b.productCode || '0')
        return pa - pb
      })
      row.isSort = true
      row.__productCode = t.map(e => e.productCode).join('/')
      row.__productName = t.map(e => e.productName).join('/')
      row.__productCategory = t.map(e => e.productCategory).join('/')
    },
    /**
     * 获取数据字典
     */
    getDataDict({ type, ditctType }) {
      const dictTypeCode = ditctType
      const appCode = 'call-center'
      const domainCode = 'marketing'
      const parmas = {
        dictTypeCode,
        appCode,
        domainCode
      }
      getDictByType(parmas).then(res => {
        const data = res.data || []
        if (Array.isArray(data)) {
          data.sort(this.arraySort('dictCode'))
          if (type === 'complaintCause') {
            // 投诉原因
            this.complaintCauseStore = data
          }
          if (type === 'productType') {
            this.productTypeOption = data.map(e => {
              e.dictCode = Number(e.dictCode)
              return e
            })
          }
          if (type === 'functionalSpace') {
            this.functionalSpaceStore = data.map(e => {
              e.dictCode = Number(e.dictCode)
              return e
            })
          }
          if (type === 'productCategory') this.productCategoryStore = data
        }
      })
    },
    /**
     * 切换购买渠道 ,初始化业务类型1
     * @param {Object} data  购买渠道
     */
    buyChannelHandle(data) {
      const channelCode = data ? Number(data.dictCode || 0) : ''
      // 根据购买渠道获取初始化业务类型
      this.formData.businessType1 = ''
      this.formData.businessType1Name = ''
      this.businessType1Option = []

      this.formData.businessType2 = []
      this.formData.businessType2Name = ''
      this.businessType2Option = []

      this.formData.bpmDeptCode = ''
      this.formData.bpmDeptName = ''
      if (!channelCode) return
      // 根据购买渠道查询一级业务类型
      searchBusinessByChannel(channelCode).then(res => {
        if (res.success === 1) {
          this.businessType1Option = res.data || []
        }
      })
    },
    initBusinessType2() {
      // 根据购买渠道和一级业务类型查询二级业务类型
      this.formData.businessType2 = []
      this.formData.businessType2Name = ''
      this.businessType2Option = []

      this.formData.bpmDeptCode = ''
      this.formData.bpmDeptName = ''
      const parmas = {
        channelCode: this.formData.buyChannel,
        businessType: this.formData.businessType1
      }
      searchBusinessTwoByChannel(parmas).then(res => {
        if (res.success === 1) {
          this.businessType2Option = res.data
        }
      })
    },
    // 查找二级业务类型=》投诉原因
    businessTypeTwoChange(dictCode, clear = true) {
      this.setBpmDepartDefault()

      // 根据二级业务类型查找对应的投诉原因
      if (clear) {
        this.$set(this.formData, 'complaintCause', '')
        this.complaintCauseOption = []
      }
      if (Number(this.formData.businessType1 || 0) !== 2) return
      if (dictCode === '') {
        return
      }
      const data = TCCMap[dictCode]
      if (!data) {
        return
      }
      this.complaintCauseOption = this.complaintCauseStore.filter(e => {
        if (e.dictCode in data) {
          return true
        }
        return false
      })
    },
    // 初始化电商平台
    getPlatformList() {
      const data = json2FormData({
        pageFlag: false
      })

      getPlatformInfoB2CECO(data).then(res => {
        if (res.success === 1) {
          this.onlinePlatformOption = res.data.records
        }
      })
    },

    /**
     * 查找产品类型->功能空间
     */
    productTypelChange(dictCode) {
      this.$set(this.formData, 'functionalSpace', '')
      this.$set(this.formData, 'productCategory', '')
      this.functionalSpaceOption = []
      this.productCategoryOption = []
      if (dictCode === '') {
        return
      }
      const data = PSCMap[dictCode]
      if (!data) {
        return
      }
      this.functionalSpaceOption = this.functionalSpaceStore.filter(e => {
        if (e.dictCode in data) {
          return true
        }
        return false
      })
    },
    /**
     * 查找功能空间->产品品类
     */
    functionalSpaceChange(dictCode) {
      this.productCategoryOption = []
      this.$set(this.formData, 'productCategory', '')
      if (dictCode === '') {
        return
      }
      const p = PSCMap[this.formData.productType]
      if (!p) {
        return
      }
      const c = p[dictCode]
      if (!c) {
        return
      }
      this.productCategoryOption = this.productCategoryStore.filter(e => {
        if (c.includes(e.dictCode) || c.includes(Number(e.dictCode))) {
          return true
        }
        return false
      })
    },
    /**
     * Object类型数组排序
     */
    arraySort(field) {
      return (a, b) => {
        const val1 = a[field]
        const val2 = b[field]
        return val1 - val2
      }
    },
    /**
     * 获取电商店铺及电商平台对应值
     */
    onlinePlatformChange(code) {
      if (code === '') {
        this.$set(this.formData, 'onlineShopCode', '')
        this.onlineShopOption = []
        return
      }
      this.$set(this.formData, 'onlineShopCode', '')
      const obj = this.onlinePlatformOption.find((item) => {
        return item.code === code
      })

      this.formData.onlinePlatformName = obj.name

      const filtersRaw = [{ id: 'platformCode', value: code, property: 'platformCode', operator: 'like' }]
      const data = json2FormData({
        filtersRaw: JSON.stringify(filtersRaw)
      })
      getStoreInfoB2CECO(data).then(res => {
        if (res.success === 1) this.onlineShopOption = res.data.records
      })
    },
    // 导出
    queryDataFun() {
      return this.querySearch('formOrder', 'export')
    },
    /**
     * 查询表单
     */
    querySearch(formName, type, onPage) {
      const v = Object.keys(this.formData).some(key => {
        return !isEmpty(this.formData[key])
      })
      if (!v) {
        this.$message({
          title: '提示',
          message: '至少填写或选择一项查询条件',
          type: 'warning'
        })
        return Promise.reject('至少填写或选择一项查询条件')
      }
      return this.$refs[formName].validate().then(() => {
        // FIXME:
        const formData = deepCopy(this.formData)
        const otherParamRows = {}
        const paramKeys = ['dispatchReceiveState', 'ccReceiveState', 'dispatchDutyDepts', 'dispatchReceiver', 'ccDutyDepts', 'ccReceiver', 'dispatchOffice', 'ccOffice', 'dispatchDisCode', 'ccDisCode', 'dispatchShopCode', 'ccShopCode', 'dispatchOperationMode', 'ccOperationMode']
        paramKeys.forEach((k) => {
          let val = ''
          if (['dispatchDutyDepts', 'ccDutyDepts'].includes(k)) {
            const valArr = formData[k] || []
            if (valArr.length > 0) {
              val = `[${valArr.join(',')}]`
            }
          } else {
            val = formData[k] === 0 ? formData[k] : formData[k] || ''
          }
          if (val instanceof Array && val.length > 0) {
            this.$set(otherParamRows, k, val)
          } else if (val !== '') {
            this.$set(otherParamRows, k, val)
          }
          delete formData[k]
        })

        delete formData.dispatchOfficeName
        delete formData.ccOfficeName
        delete formData.dispatchDisName
        delete formData.ccDisName
        delete formData.ccDisId
        delete formData.dispatchDisId
        delete formData.dispatchShopName
        delete formData.ccShopName
        delete formData.nextHandlerName

        // 处理nextHandler
        if (formData.nextHandler instanceof Array && formData.nextHandler.length > 0) {
          formData.nextHandler = `[${formData.nextHandler.join(',')}]`
        }
        // 处理工单状态
        if (formData.workOrderState instanceof Array && formData.workOrderState.length > 0) {
          formData.workOrderState = `[${formData.workOrderState.join(',')}]`
        }
        // 处理维修进度
        if (formData.processRate instanceof Array && formData.processRate.length > 0) {
          formData.processRate = `[${formData.processRate.join(',')}]`
        }
        // 紧急程度
        if (formData.urgencyDegree instanceof Array && formData.urgencyDegree.length > 0) {
          formData.urgencyDegree = `[${formData.urgencyDegree.join(',')}]`
        }
        // 处理方案
        if (formData.handleScheme instanceof Array && formData.handleScheme.length > 0) {
          formData.handleScheme = `[${formData.handleScheme.join(',')}]`
        }
        // 业务类型2
        if (formData.businessType2 instanceof Array && formData.businessType2.length > 0) {
          formData.businessType2 = `[${formData.businessType2.join(',')}]`
        }
        // 支付方式
        if (formData.paymentMode instanceof Array && formData.paymentMode.length > 0) {
          formData.paymentMode = `[${formData.paymentMode.join(',')}]`
        }

        // 预约送货时间
        if (Array.isArray(formData.deliveryTime) && formData.deliveryTime.length) {
          formData.deliveryTime[1] = this.addDay(formData.deliveryTime[1], 1)
        }
        // 送装预约时间
        /*  if (Array.isArray(formData.bookingServiceTime) && formData.bookingServiceTime.length) {
          formData.bookingServiceTime[1] = this.addDay(formData.bookingServiceTime[1], 1)
        } */
        // 下单时间
        if (Array.isArray(formData.orderTime) && formData.orderTime.length) {
          formData.orderTime[1] = this.addDay(formData.orderTime[1], 1)
        }
        // 创建时间
        if (Array.isArray(formData.createTime) && formData.createTime.length) {
          formData.createTime[1] = this.addDay(formData.createTime[1], 1)
        }
        // 派单时间
        /* if (Array.isArray(formData.dispatchTime) && formData.dispatchTime.length === 2) {
          formData.dispatchTime[1] = this.addDay(formData.dispatchTime[1], 1)
        } */
        // 结案时间
        if (Array.isArray(formData.finishTime) && formData.finishTime.length === 2) {
          formData.finishTime[1] = this.addDay(formData.finishTime[1], 1)
        }
        // 处理截止时间
        /* if (Array.isArray(formData.processingDeadline) && formData.processingDeadline.length) {
          formData.processingDeadline[1] = this.addDay(formData.processingDeadline[1], 1)
        } */

        /*
        TODO:待确认以下字段处理 like '% ,%' 是否由前端处理
        // 服务费类型
        if (formData.serviceFeeType) {
          formData.serviceFeeType = `${formData.serviceFeeType},`
        }
        // 费用类型
        if (formData.feeType) {
          formData.feeType = `${formData.feeType},`
        }
        // 赔付原因
        if (formData.compensationCause) {
          formData.compensationCause = `${formData.compensationCause},`
        }
        // 投诉原因
        if (formData.complaintCause) {
          formData.complaintCause = `${formData.complaintCause},`
        }
        // 被投诉对象
        if (formData.complaintObject) {
          formData.complaintObject = `${formData.complaintObject},`
        }
        // 顾客不认可原因
        if (formData.customerDisapprovalCause) {
          formData.customerDisapprovalCause = `${formData.customerDisapprovalCause},`
        }
        // 产品问题
        if (formData.productProblem) {
          formData.productProblem = `${formData.productProblem},`
        } */

        this.disposeOrderParams = [...ArrayFormat(formData, {
          nextHandler: 'in', nextHandlerPlatformNo: '=', handlerGroupNo: '=', handlerPostCode: '',
          contactName: '=', contactPhone: '=', nickname: '=', orderCode: '=', ecOrderNumber: '=',
          workOrderCode: '=', workOrderState: 'in', processRate: 'in',
          buyChannel: '=', channelType: '=', businessType1: '=', businessType2: 'in', repairsReason: 'like',
          complaintCause: 'like', complaintObject: 'like', customerDisapprovalCause: 'like',
          complaintType: '=',
          serviceFeeType: 'like', feeType: 'like', compensationCause: 'like',
          invoiceSubBusiness: '=',
          productProblem: 'like',
          transportationLossType: '=',
          productType: '=', functionalSpace: '=', productCategory: '=',
          urgencyDegree: 'in', urgencyCause: '=',
          onlinePlatformCode: '=', onlineShopCode: '=',
          deliveryMethod: '=', deliveryTime: ['>', '<'],
          isOverdue: '=', overdueReason: '=', isTimeoutOrder: '=', isTimeout: '=',
          createBy: '=', createByPlatformNo: '=', createByGroupNo: '=',
          handleScheme: 'in', paymentMode: 'in',
          deliveryNeed: '=', bookingServiceTime: ['>', '<'], returnsCause: '=',
          orderTime: ['>', '<'], timeoutReason: '=',
          patchCode: '=', isTwoCheckComputation: '=', isCare: '=',

          afterSalesCall: '=',
          officeCode: '=',
          disCode: '=',
          customerApplyStatus: '=',

          createTime: ['>', '<'],
          dispatchTime: ['>', '<'],
          finishTime: ['>', '<'],
          processingDeadline: ['>', '<'],
          sourceSystem: '='
        })]
        this.otherParamRows = otherParamRows
        if (type !== 'export') {
          this.refreshTableBox(onPage)
        }
        return this.disposeOrderParams
      })
    },
    // 刷新数据
    refreshTableBox(onPage) {
      this.$nextTick(() => {
        this.$refs.table.initTableData(onPage)
      })
    },
    // 重置表单
    resetSearch(formName) {
      const excludeArr = ['processingDeadline', 'createTime']
      Object.keys(this.formData).forEach(k => {
        if (excludeArr.indexOf(k) !== -1) this.$set(this.formData, k, [])
        this.$set(this.formData, k, '')
      })
      this.$refs[formName].resetFields()
      if (!this.query) {
        const { account, userName } = this.$store.state.user.user
        account ? this.formData.nextHandler = [account] : this.formData.nextHandler = []
        userName ? this.formData.nextHandlerName = [userName] : this.formData.nextHandlerName = []
      }
    },
    /**
     * 跳转详细
     */
    columnClickHandle(row) {
      if (this.query) {
        // 查询
        this.$router.push({ name: 'QueryOrderDetails', query: { id: row.id }})
      } else {
        // 处理
        if (row.workOrderState === 0) {
          this.$router.push({ name: 'CreateOrder', query: { id: row.id, state: row.workOrderState, type: 'edit' }})
        } else {
          this.$router.push({ name: 'DisposeOrderDetails', query: { id: row.id }})
        }
      }
    },
    /**
     * 重置办事处以下信息
     */
    resetOfficeName() {
      const _this = this
      _this.$set(_this.formData, 'officeCode', '')
      _this.$set(_this.formData, 'officeName', '')
      _this.$set(_this.formData, 'disCode', '')
      _this.$set(_this.formData, 'disName', '')
      _this.$set(_this.formData, 'shopCode', '')
      _this.$set(_this.formData, 'shopName', '')
      _this.$set(_this.formData, 'afterSalesCall', '')
      _this.shopCallTel = []
    },
    /**
     * 重置经销商以下相关信息
     */
    resetDisName() {
      const _this = this
      _this.$set(_this.formData, 'disCode', '')
      _this.$set(_this.formData, 'disName', '')
      _this.$set(_this.formData, 'shopCode', '')
      _this.$set(_this.formData, 'shopName', '')
      _this.$set(_this.formData, 'afterSalesCall', '')
      _this.shopCallTel = []
    },
    /**
     * 重置门店信息
     */
    resetShopInfo() {
      const _this = this
      _this.$set(_this.formData, 'shopCode', '')
      _this.$set(_this.formData, 'shopName', '')
      _this.$set(_this.formData, 'afterSalesCall', '')
      _this.shopCallTel = []
    },
    // 日期加1
    addDay(datetime, days) {
      const old_time = new Date(datetime.replace(/-/g, '/'))
      const fd = new Date(old_time.valueOf() + days * 24 * 60 * 60 * 1000)
      let new_time = fd.getFullYear() + '-'
      const month = fd.getMonth() + 1
      if (month >= 10) {
        new_time += month + '-'
      } else {
        // 在小于10的月份上补0
        new_time += '0' + month + '-'
      }
      if (fd.getDate() >= 10) {
        new_time += fd.getDate()
      } else {
        // 在小于10的日期上补0
        new_time += '0' + fd.getDate()
      }
      return new_time
    },
    // 导出
    exportFile() {
      return this.queryDataFun().then(data => {
        const body = {
          pageFlag: true,
          filtersRaw: data,
          rows: 10000,
          page: 1
        }
        return workOrderExport(pageRequsetBody(body))
      })
    },
    // 处理选择项
    selectionChange(v) {
      this.selectedArry = v
    },
    /**
     * 获取组类别
     */
    initBusinessOption() {
      getBusinessAll().then(res => {
        if (res.success === 1) {
          this.businessOptions = res.data
        }
      })
    },
    handleDateTimeRageFocus(filed) {
      const val = this.formData[filed]
      if (!val || val.length === 0) {
        const today = parseTime(new Date(), '{y}-{m}-{d}')
        const defautVal = [`${today} 00:00:00`, `${today} 21:00:00`]
        this.$set(this.formData, filed, defautVal)
      }
    },
    // 办事处相关
    officeChange() {
      this.$set(this.formData, 'disCode', '')
      this.$set(this.formData, 'disName', '')
    }
  }
}
</script>
<style lang="scss" scoped>
.disposeOrder .content-wrap /deep/ .el-form .el-row .el-col-4 {
  width: 20% !important;
}
.disposeOrder .content-wrap /deep/ .el-form .el-row .el-col-9 {
  width: 40% !important;
}
.disposeOrder /deep/ .el-tooltip .table-other span.table-handelclick-text {
  color: #3DC094;
  cursor: pointer;
}
</style>
<style lang="scss" module>
  .wrap{
    tr{
      background-color: white !important;
    }
  }
</style>
